package ui.graphical;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import javax.swing.JButton;

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;

import logic.Logic;
import javax.swing.ImageIcon;

public class Hoofdmenu extends JFrame implements ActionListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3201166107651257854L;
	private JButton btnReizen;
	private JButton btnReserveringen;
	private JButton btnPersonen;
	private JButton btnKortingen;
	private Reizen reizenFrame = null;
	private Personen personenFrame = null;
	private Reserveringen reserveringenFrame = null;
	private Kortingen kortingenFrame = null;
	
	public Hoofdmenu(Logic logic) {
		SplashScreen splashScreen = new SplashScreen();
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {
			e.printStackTrace();
		}
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setResizable(false);
		
		setIconImage(Toolkit.getDefaultToolkit().getImage(".\\images\\sm_reizen.jpg"));
		setTitle("Shoestring Backoffice");
		
		btnReizen = new JButton("Reizen");
		btnReizen.setToolTipText("");
		btnReizen.setIcon(new ImageIcon(".\\images\\sm_reizen.jpg"));
		btnReizen.setBounds(0, 0, 240, 135);
		btnReizen.addActionListener(this);
		getContentPane().setLayout(null);
		getContentPane().add(btnReizen);
		
		btnPersonen = new JButton("Personen");
		btnPersonen.setToolTipText("");
		btnPersonen.setIcon(new ImageIcon(".\\images\\sm_reizigers.jpg"));
		btnPersonen.setBounds(240, 0, 240, 135);
		getContentPane().add(btnPersonen);
		btnPersonen.addActionListener(this);
		
		btnReserveringen = new JButton("Reserveringen");
		btnReserveringen.setToolTipText("");
		btnReserveringen.setIcon(new ImageIcon(".\\images\\sm_reserveringen.jpg"));
		btnReserveringen.setBounds(480, 0, 240, 135);
		getContentPane().add(btnReserveringen);
		btnReserveringen.addActionListener(this);
		
		btnKortingen = new JButton("Kortingen");
		btnKortingen.setToolTipText("");
		btnKortingen.setIcon(new ImageIcon(".\\images\\sm_kortingen.jpg"));
		btnKortingen.setBounds(720, 0, 240, 135);
		getContentPane().add(btnKortingen);
		btnKortingen.addActionListener(this);
		
		setBounds(new Rectangle(0, 0, 965, 160));
		// centreer window
		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		setBounds((dim.width-getWidth())/2,0,965,160);
		
		reizenFrame = new Reizen(logic);
		UIHelper.centreerFrame(reizenFrame);
		kortingenFrame = new Kortingen(logic);
		UIHelper.centreerFrame(kortingenFrame);
		personenFrame = new Personen(logic);
		UIHelper.centreerFrame(personenFrame);
		reserveringenFrame = new Reserveringen(logic);
		UIHelper.centreerFrame(reserveringenFrame);
		setVisible(true);
		splashScreen.dispose();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource().equals(btnReizen)) {
			reizenFrame.setVisible(true);
			reizenFrame.toFront();
		}
		else if(e.getSource().equals(btnKortingen)) {
			kortingenFrame.setVisible(true);
			kortingenFrame.toFront();
		}
		else if(e.getSource().equals(btnPersonen)) {
			personenFrame.setVisible(true);
			personenFrame.toFront();
		}
		else if(e.getSource().equals(btnReserveringen)) {
			reserveringenFrame.setVisible(true);
			reserveringenFrame.toFront();
		}
	}
}
